package com.ruijie.autotest.log.validation.hangzhouxiruan;

import com.ruijie.autotest.log.core.data.IRow;
import com.ruijie.autotest.log.core.data.ITable;
import com.ruijie.autotest.log.core.validate.IValidator;
import org.springframework.context.ApplicationContext;

public class ColumnVerification implements IVerification {
	private final ApplicationContext validators;

	private final ITable table;

	public ColumnVerification(ApplicationContext validators, ITable table) {
		this.validators = validators;
		this.table = table;
	}

	@Override
	public void verify() {
		// processing detail
		System.out.println("not we are verifying: " + table);
		for (IRow row : table) {
			for (String columnName : row.columns()) {
				// get the configured Validator
				String actualValue = row.stringValueOf(columnName);
				boolean validate = createValidator(columnName).validate(actualValue);
				if (validate) {
					System.out.println("passed.");
				} else {
					System.out.println("failure found: " + columnName + " with it's value: " + actualValue);
				}
				System.out.println(); // next line
			}
		}
	}

	// FIXME 2021/1/16  wait for me!!!   to Factory
	private IValidator createValidator(String columnName) {
		return (IValidator) validators.getBean(columnName + "Validator");
	}
}
